//
//  DCAuthFooterView.m
//  Demo
//
//  Created by zhaolin on 2023/1/12.
//

#import "DCAuthFooterView.h"


@interface DCAuthFooterView ()

@property (nonatomic, strong) UIButton *commitBtn;

@property (nonatomic, strong) UIButton *privacyBtn;

@end

@implementation DCAuthFooterView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self configureUI];
    }
    return self;
}

- (void)configureUI {
    self.backgroundColor = [UIColor colorWithString:@"#FFFFFF"];
    UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _commitBtn = nextBtn;
    nextBtn.layer.cornerRadius = 8;
    nextBtn.layer.masksToBounds = YES;
    nextBtn.backgroundColor = [UIColor colorWithString:@"#CED7CD"];
    nextBtn.titleLabel.font = DCFont_PF_Semibold(15);
    [nextBtn setTitleColor:[UIColor colorWithString:@"#FFFFFF"] forState:UIControlStateNormal];
    [nextBtn setTitle:@"Next" forState:UIControlStateNormal];
    [nextBtn addTarget:self action:@selector(nextBtnAtion:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:nextBtn];
    [nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(30);
        make.left.mas_equalTo(38);
        make.right.mas_equalTo(-38);
        make.height.mas_equalTo(50);
    }];

    UIView *placeView = [UIView new];
    placeView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:placeView];
    [placeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(nextBtn.mas_bottom);
    }];
    
    UIButton *agreementBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _privacyBtn = agreementBtn;
    agreementBtn.titleLabel.font = DCFont_PF_Regular(11);
    [agreementBtn setTitleColor:[UIColor colorWithString:@"#000000"] forState:UIControlStateNormal];
    [agreementBtn setTitle:@"《Privacy Agreement》" forState:UIControlStateNormal];
    [agreementBtn addTarget:self action:@selector(pushPrivacyAgreement) forControlEvents:UIControlEventTouchUpInside];
    [placeView addSubview:agreementBtn];
    [agreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.mas_equalTo(placeView);
    }];
}

- (void)nextBtnAtion:(UIButton *)sender {
    if(self.delegate && [self.delegate respondsToSelector:@selector(authFooterViewNextAction:)]) {
        [self.delegate authFooterViewNextAction:self];
    }
}

- (void)pushPrivacyAgreement{
    if(self.delegate && [self.delegate respondsToSelector:@selector(authFooterViewAgreementAction:)]) {
        [self.delegate authFooterViewAgreementAction:self];
    }
}

- (void)setCommitBtnEnabled:(BOOL)enabled {
//    _commitBtn.enabled = enabled;
    _commitBtn.backgroundColor = enabled ? [UIColor colorWithString:@"#1C221B"] : [UIColor colorWithString:@"#CED7CD"];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
